package ChessEngine;

import boardData.*;

public class SimpleEvaluator extends AbstractEvalutor{	
	private int blackMatCount;
	private int whiteMatCount;
	
	public SimpleEvaluator() {	
	}
	
	@Override
	public int evaluate(Board b) {
		int whiteScore = countWhiteScore(b);
		int blackScore = countBlackScore(b);
		
		//return countWhiteScore(b) - countBlackScore(b);
		return whiteScore - blackScore;
	}		
	
	public int countBlackScore(Board b){
		
		int blackScore=0;
		for(int i=0; i<b.getArrayLength();i++){
			
			switch(b.getPiece(i))
			{
				case Pieces.PieceValues.BLACK_BISHOP :	
					blackScore += AbstractEvalutor.BISHOP_SCORE;
				break;
				
				case Pieces.PieceValues.BLACK_KING	 :	
					blackScore += AbstractEvalutor.KING_SCORE;
				break;
				
				case Pieces.PieceValues.BLACK_KNIGHT :	
					blackScore += AbstractEvalutor.KNIGHT_SCORE;
				break;
				
				case Pieces.PieceValues.BLACK_PAWN	 : 	
					blackScore += AbstractEvalutor.PAWN_SCORE;
				break;
				
				case Pieces.PieceValues.BLACK_QUEEN	 : 	
					blackScore += AbstractEvalutor.QUEEN_SCORE;
				break;
				
				case Pieces.PieceValues.BLACK_ROOK	 : 	
					blackScore += AbstractEvalutor.ROOK_SCORE;
				break;
			}
		}		
		blackMatCount = blackScore;
		return blackScore;
	}
	
	public int countWhiteScore(Board b){
		
		int whiteScore=0;
		
		for(int i=0; i<b.getArrayLength();i++){
			
			switch(b.getPiece(i))
			{
				case Pieces.PieceValues.WHITE_BISHOP	:	
					whiteScore += AbstractEvalutor.BISHOP_SCORE;
				break;
				
				case Pieces.PieceValues.WHITE_KING		:	
					whiteScore += AbstractEvalutor.KING_SCORE;
				break;
				
				case Pieces.PieceValues.WHITE_KNIGHT	:	
					whiteScore += AbstractEvalutor.KNIGHT_SCORE;
				break;
				
				case Pieces.PieceValues.WHITE_PAWN		:  	
					whiteScore += AbstractEvalutor.PAWN_SCORE;
				break;
				
				case Pieces.PieceValues.WHITE_QUEEN		: 	
					whiteScore += AbstractEvalutor.QUEEN_SCORE;
				break;
				
				case Pieces.PieceValues.WHITE_ROOK		: 	
					whiteScore += AbstractEvalutor.ROOK_SCORE;
				break;
			}
		}		
		whiteMatCount=whiteScore;
		return whiteScore;
	}

	public int getBlackMatCount() {
		return blackMatCount;
	}

	public int getWhiteMatCount() {
		return whiteMatCount;
	}
	
	
	
}
	
	